<?php

namespace core;
class Config
{
    static public $config = array();

    static public function get($name, $file)
    {
        //判断配置文件是否存在
        //判断配置是否存在
        //缓存配置

        $path = H5ROOT . '/core/config/' . $file . '.php';
        if (isset(self::$config[$file])) {
            if (isset(self::$config[$file][$name])) {
                return self::$config[$file][$name];
            }else {
                throw new \Exception('找不到配置项: ' . $name);
            }
        } else {
            if (is_file($path)) {
                $conf = include $path;
                if (isset($conf[$name])) {
                    //缓存配置
                    self::$config[$file] = $conf;
                    //返回配置
                    return $conf[$name];
                } else {
                    throw new \Exception('找不到配置项: ' . $name);
                }
            } else {
                throw new \Exception('找不到配置文件: ' . $file);
            }
        }
    }

   static public function all($file)
    {
        if(isset(self::$config[$file])){
            return self::$config[$file];
        }else{
            $path = H5ROOT.'/core/config/'.$file.'.php';
            if(is_file($path)){
                $conf = include $path;
                self::$config[$file] = $conf;
                return $conf;
            }else{
                throw new \Exception('找不到配置文件'.$file);
            }
        }
    }
}
